//
//  LMAddViewController.m
//  20.私人通讯录
//
//  Created by 张青花 on 15/8/27.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMAddViewController.h"
#import "LMPhone.h"

@interface LMAddViewController ()
/**
 *  用户名
 */
@property (weak, nonatomic) IBOutlet UITextField *userField;
/**
 *  密码
 */
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
/**
 *  保存
 */
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;

@end

@implementation LMAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    
    [center addObserver:self selector:@selector(changeBtn) name:UITextFieldTextDidChangeNotification
                 object:self.userField];
    [center addObserver:self selector:@selector(changeBtn) name:UITextFieldTextDidChangeNotification
                 object:self.pwdField];
    
    
    [self.userField becomeFirstResponder];
}
//改变登录状态
- (void)changeBtn
{
    self.saveBtn.enabled = (self.userField.text.length>0&&self.pwdField.text.length);
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (IBAction)saveBtnOnclick:(id)sender {
    
    LMPhone * phone = [[LMPhone alloc] init];
    
    phone.username = self.userField.text;
    phone.number = self.pwdField.text;
    
    
    if ([self.deleage respondsToSelector:@selector(addViewController:phone:)]) {
        [self.deleage addViewController:self phone:phone];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
